class Solution {
    public static  int search(int[] nums, int target) {
        int left = 0, right = nums.length;
        while (left < right) {
            int mid = left + ((right - left) >> 1);
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] < target)
                left = mid + 1;
            else if (nums[mid] > target)
                right = mid;
        }
        return -1;
    }
    public static  void main(String[] args){
        int [] a={1,2,3,4,5,6,7,8,9};
        System.out.println(search(a,4));
    }
}


